import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import eslint from 'vite-plugin-eslint'
import vueJsx from '@vitejs/plugin-vue-jsx'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    eslint({
      cache: false
    }),
    vueJsx(),
    // element-plus
    AutoImport({
      dts: true,
      // Auto import functions from Vue, e.g. ref, reactive, toRef...
      // 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
      imports: ['vue'],
      resolvers: [
        ElementPlusResolver(),
        // Auto import icon components
        // 自动导入图标组件
        IconsResolver({
          // prefix: 'Icon', // 好像没什么卵用
        }),
      ],
    }),
    Components({
      resolvers: [
        // Auto register icon components
        // 自动注册图标组件
        IconsResolver({
          // enabledCollections: ['ep'],
        }),
        ElementPlusResolver(),

      ],
    }),
    Icons({
      autoInstall: true,
    })
  ],
  resolve: {
    alias: {
      '@': path.join(__dirname, 'src')
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import '@/styles/variables.scss'; @import '@/styles/mixin.scss';`
      },
    }
  },
  server: {
    proxy: {
      // 选项写法
      '/api': {
        target: 'https://shop.fed.lagounews.com/api/admin',
        // 兼容基于名字的虚拟主机
        // 开发模式下默认的origin 是 localhost:xxx
        // 代理服务器会把 origin 修改为 目标地址
        changeOrigin: true,
        // 路径重写
        rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }

})
